<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsp/sys/include.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>"/>
<title>用户管理</title>
<link href="css/global.css" type="text/css" rel="stylesheet"/>
	<script src="js/jquery-1.5.1.js" type="text/javascript"></script>
		<link rel="stylesheet" type="text/css" href="css/easydialog.css" />
	<script src="js/jquery.form.js" type="text/javascript"></script>
	<script src="js/easydialog.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/dtree.js"></script>
<link href="css/dtree.css" rel="stylesheet" type="text/css"></link>

<style type="text/css">
<!--
body{
	background-color:#f8ffd3;
	margin:0px; padding:0px;
}
#roletree{
	border:1px solid #85B6E2;
	margin: 5px;
	padding: 5px;
}
#rolecontrl{
	margin: 5px;
	padding: 5px;
}
.cx{
}
-->
</style>
<script>
//分配菜单
function settleMenu(data_id){
	var url="sysRoleSetMenu.do?id="+data_id;
	window.location=url;
	window.reload();
	
}
</script>
</head>
	<body>
	<%--
	<input value="asd" onclick="javascirpt:alert(document.getElementById('main').innerHTML)"/>
	 --%>
	<div id="main">

	<div id="part1" class="part">
		<p class="title"><a href="#">分配角色</a></p>
		<div class="doc" id="doc2">
		<form action="">
			<div id="roletree">
				<div id="systree"></div>
			</div>
			<div id="rolecontrl">
			<input type="button" class="btn" value="打开" disabled="disabled" onclick="javascript: d.openAll();"/>
			<input type="button" class="btn" value="关闭" disabled="disabled" onclick="javascript: d.closeAll();"/>
			<input type="button" class="btn" value="提交" onclick="submitForm()"/>
			<input type="reset" class="btn" disabled="disabled"  value="重置"/>
			</div>
		</form>
		
			
		</div>
	</div>
	
	
<!-- javascript -->
<script type="text/javascript">
	function sel(){
		var selids=d.getCheckedNodes();
		var str="";
		for(var n=0; n<selids.length; n++){
			str+=selids[n]+";";
		}
		alert(str);
	}
	var d = new dTree('d','img/system/dept/');
	d.config.folderLinks=true;
	d.config.useCookies=false;
	d.config.check=true;
		d.add(0,-1,'设置角色',"javascript:;",'提示');
		
		<c:forEach items="${allRoles}" var="role">
			d.add(${role.id},0,'${role.name}',"javascript:void(0);",'${role.description}');
		</c:forEach>
		
	document.getElementById('systree').innerHTML = d;
	
	var funcs = eval("("+"{funcs:[${userRoles}]}"+")");
	for(var n=0; n<funcs.funcs.length;n++){
		d.co(funcs.funcs[n].menudm).checked=true;
	}
	
	//提交
	function submitForm(){
		var valueStr='';
		$('input:checkbox').each(function() {
            if ($(this).attr('checked') ==true) {
                //alert($(this).val());
                valueStr=valueStr+$(this).val()+",";
            }
        });
		
		$.ajax({
 			url:"sysUserSetRoleAction.do",
 			//防止浏览器缓存，在URL后加时间戳 "&timestamp=" + (new Date()).getTime()
 			data:encodeURI("id=" + ${id} + "&roleIds=" + valueStr + "&timestamp=" + (new Date()).getTime()),
 			dataType:"json",
 			success:function(data){
 				alert(data);
 				if("true" == data){
	       			
	       			easyDialog.open({
					container : {
						header : '信息提示',
						content : '数据提交成功！',
						yesFn : function(){
	       							//return true;
	       							window.location="sysUserQuery.do";
	       							window.reload();
	       							}
					}
				});
						         			
	       		}else if("repeatSubmit" == data){
	       			easyDialog.open({
					container : {
						header : '信息提示',
						content : '数据已提交，请不要重复操作！',
						yesFn : function(){return true;}
					}
				});
	       		}else{
	       			
	       			easyDialog.open({
					container : {
						header : '信息提示',
						content : '数据提交失败！',
						yesFn : function(){return true;}
					}
 				 });
				 }
 			}
 		});
 			
		
	}
</script>
	</body>
</html>

